<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>扩展运算符</title>
  </head>
  <body>
    <p>扩展运算符(...) 将数组转换为用逗号分隔的参数序列</p>
    <pre>
          console.log(...[1,2,3])
    </pre>
    <p>扩展运算符主要用于函数调用</p>
    <pre>
            function push(array,...item){
              array.push(...item)
            }
            function add(x,y){
              return x+y;
            }
        let numbers= [4, 38] ;     
        add(...numbers)
      </pre
    >
    <p>数组合并</p>
    <pre>
     let arr1 = ["a", "b"];
     let arr2 = ["c"];
     let arr3 = ["d", "e"];
      //es6
     console.log([...arr1, ...arr2, ...arr3]);
      //es5
     console.log(arr1.concat(arr2, arr3))
    </pre>

    <p>与解构赋值结合生成数组</p>

    <pre>
      let list=[1,2,3]
      //es5  
      var a=list[0];
      var rest=list.slice(1);
      //es6
      [a,...rest]=list
    </pre>
  </body>
</html>
<script>
  console.log(...[1, 2, 3]);
  function push(array, ...item) {
    array.push(...item);
  }
  function add(x, y) {
    console.log(x + y);
  }
  let numbers = [4, 38];
  add(...numbers);
  let arr1 = ["a", "b"];
  let arr2 = ["c"];
  let arr3 = ["d", "e"];
  //es6
  console.log([...arr1, ...arr2, ...arr3]);
  //es5
  console.log(arr1.concat(arr2, arr3));
</script>
